import { ipcApiRoute } from '@/api/router'
import { ipc } from './ipcRenderer'
import { emitter } from './mitt'

const getElectronHttp = (): Promise<string> => {
  return new Promise((resolve, reject) => {
    ipc.invoke(ipcApiRoute.checkHttpServer, {}).then((res: { enable: any; server: string }) => {
      if (res.enable) {
        resolve(res.server || 'http://localhost:7071')
      } else {
        reject('http服务未启用！')
      }
    })
  })
}

export { emitter, ipc, getElectronHttp }
